package com.bdqn.t382.controller;

import com.bdqn.t382.pojo.Electron;
import com.bdqn.t382.service.ElectronService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
public class ElectronController {
    @Autowired
    private ElectronService electronService;

    @RequestMapping("/electron")
    public String electron(Model model) {
        List<Electron> list = electronService.ElectronListBiz(new Electron());
        model.addAttribute("list", list);
        return "electron";
    }

    @GetMapping("/addPage")
    public String showAddPage() {
        return "add";
    }

    @PostMapping("/add")
    public String add(Electron electron) {
        int biz = electronService.insertBiz(electron);
        if (biz > 0) {
            return "redirect:/electron";
        } else {
            return "redirect:/error";
        }
    }
}
